/*******************************************************************************
 *                                    ZLG
 *                         ----------------------------
 *                         innovating embedded platform
 *
 * Copyright (c) 2001-present Guangzhou ZHIYUAN Electronics Co., Ltd.
 * All rights reserved.
 *
 * Contact information:
 * web site:    https://www.zlg.cn
 *******************************************************************************/
#ifndef __HC32F4A0_REGS_EFM_H
#define __HC32F4A0_REGS_EFM_H

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus*/
#include "core/include/hc32f4a0_regs_base.h"
#include "common/hc32f4a0_common.h"


/* \brief FLASH 密钥*/
#define EFM_SECRET_KEY1              (0x0123U)
#define EFM_SECRET_KEY2              (0x3210U)

/* \brief EFM 等待循环*/
#define EFM_WAIT_CYCLE_0                   (0U)      /* 不插入读等待周期 */
#define EFM_WAIT_CYCLE_1                   (1U)      /* 插入1个读等待周期  */
#define EFM_WAIT_CYCLE_2                   (2U)      /* 插入2个读等待周期  */
#define EFM_WAIT_CYCLE_3                   (3U)      /* 插入3个读等待周期 */
#define EFM_WAIT_CYCLE_4                   (4U)      /* 插入4个读等待周期 */
#define EFM_WAIT_CYCLE_5                   (5U)      /* 插入5个读等待周期 */
#define EFM_WAIT_CYCLE_6                   (6U)      /* 插入6个读等待周期  */
#define EFM_WAIT_CYCLE_7                   (7U)      /* 插入7个读等待周期  */
#define EFM_WAIT_CYCLE_8                   (8U)      /* 插入8个读等待周期  */
#define EFM_WAIT_CYCLE_9                   (9U)      /* 插入9个读等待周期  */
#define EFM_WAIT_CYCLE_10                  (10U)     /* 插入10个读等待周期 */
#define EFM_WAIT_CYCLE_11                  (11U)     /* 插入11个读等待周期 */
#define EFM_WAIT_CYCLE_12                  (12U)     /* 插入12个读等待周期 */
#define EFM_WAIT_CYCLE_13                  (13U)     /* 插入13个读等待周期 */
#define EFM_WAIT_CYCLE_14                  (14U)     /* 插入14个读等待周期 */
#define EFM_WAIT_CYCLE_15                  (15U)     /* 插入15个读等待周期 */

/* \brief EFM FRMC 读模式寄存器位定义 */
#define EFM_FRMC_FLWT_POS                              (0U)
#define EFM_FRMC_FLWT                                  (0x0000000FUL)
#define EFM_FRMC_LVM_POS                               (8U)
#define EFM_FRMC_LVM                                   (0x00000100UL)
#define EFM_FRMC_ICACHE_POS                            (16U)
#define EFM_FRMC_ICACHE                                (0x00010000UL)
#define EFM_FRMC_DCACHE_POS                            (17U)
#define EFM_FRMC_DCACHE                                (0x00020000UL)
#define EFM_FRMC_PREFE_POS                             (18U)
#define EFM_FRMC_PREFE                                 (0x00040000UL)
#define EFM_FRMC_CRST_POS                              (19U)
#define EFM_FRMC_CRST                                  (0x00080000UL)

/* \brief EFM FWMC 擦写模式寄存器位定义 */
#define EFM_FWMC_PEMOD_POS                             (0U)
#define EFM_FWMC_PEMOD                                 (0x00000007UL)
#define EFM_FWMC_BUSHLDCTL_POS                         (8U)
#define EFM_FWMC_BUSHLDCTL                             (0x00000100UL)
#define EFM_FWMC_KEY1LOCK_POS                          (16U)
#define EFM_FWMC_KEY1LOCK                              (0x00010000UL)
#define EFM_FWMC_KEY2LOCK_POS                          (17U)
#define EFM_FWMC_KEY2LOCK                              (0x00020000UL)

/* \brief EFM FSTP 停止寄存器位定义  */
#define EFM_FSTP_F0STP_POS                             (0U)
#define EFM_FSTP_F0STP                                 (0x00000001UL)
#define EFM_FSTP_F1STP_POS                             (1U)
#define EFM_FSTP_F1STP                                 (0x00000002UL)

/* \brief EFM FSR 状态寄存器位定义 */
#define EFM_FSR_OTPWERR0_POS                           (0U)
#define EFM_FSR_OTPWERR0                               (0x00000001UL)
#define EFM_FSR_PRTWERR0_POS                           (1U)
#define EFM_FSR_PRTWERR0                               (0x00000002UL)
#define EFM_FSR_PGSZERR0_POS                           (2U)
#define EFM_FSR_PGSZERR0                               (0x00000004UL)
#define EFM_FSR_MISMTCH0_POS                           (3U)
#define EFM_FSR_MISMTCH0                               (0x00000008UL)
#define EFM_FSR_OPTEND0_POS                            (4U)
#define EFM_FSR_OPTEND0                                (0x00000010UL)
#define EFM_FSR_COLERR0_POS                            (5U)
#define EFM_FSR_COLERR0                                (0x00000020UL)
#define EFM_FSR_RDY0_POS                               (8U)
#define EFM_FSR_RDY0                                   (0x00000100UL)
#define EFM_FSR_PRTWERR1_POS                           (17U)
#define EFM_FSR_PRTWERR1                               (0x00020000UL)
#define EFM_FSR_PGSZERR1_POS                           (18U)
#define EFM_FSR_PGSZERR1                               (0x00040000UL)
#define EFM_FSR_MISMTCH1_POS                           (19U)
#define EFM_FSR_MISMTCH1                               (0x00080000UL)
#define EFM_FSR_OPTEND1_POS                            (20U)
#define EFM_FSR_OPTEND1                                (0x00100000UL)
#define EFM_FSR_COLERR1_POS                            (21U)
#define EFM_FSR_COLERR1                                (0x00200000UL)
#define EFM_FSR_RDY1_POS                               (24U)
#define EFM_FSR_RDY1                                   (0x01000000UL)

/* \brief EFM FSCLR 状态清除寄存器位定义 */
#define EFM_FSCLR_OTPWERRCLR0_POS                      (0U)
#define EFM_FSCLR_OTPWERRCLR0                          (0x00000001UL)
#define EFM_FSCLR_PRTWERRCLR0_POS                      (1U)
#define EFM_FSCLR_PRTWERRCLR0                          (0x00000002UL)
#define EFM_FSCLR_PGSZERRCLR0_POS                      (2U)
#define EFM_FSCLR_PGSZERRCLR0                          (0x00000004UL)
#define EFM_FSCLR_MISMTCHCLR0_POS                      (3U)
#define EFM_FSCLR_MISMTCHCLR0                          (0x00000008UL)
#define EFM_FSCLR_OPTENDCLR0_POS                       (4U)
#define EFM_FSCLR_OPTENDCLR0                           (0x00000010UL)
#define EFM_FSCLR_COLERRCLR0_POS                       (5U)
#define EFM_FSCLR_COLERRCLR0                           (0x00000020UL)
#define EFM_FSCLR_PRTWERRCLR1_POS                      (17U)
#define EFM_FSCLR_PRTWERRCLR1                          (0x00020000UL)
#define EFM_FSCLR_PGSZERRCLR1_POS                      (18U)
#define EFM_FSCLR_PGSZERRCLR1                          (0x00040000UL)
#define EFM_FSCLR_MISMTCHCLR1_POS                      (19U)
#define EFM_FSCLR_MISMTCHCLR1                          (0x00080000UL)
#define EFM_FSCLR_OPTENDCLR1_POS                       (20U)
#define EFM_FSCLR_OPTENDCLR1                           (0x00100000UL)
#define EFM_FSCLR_COLERRCLR1_POS                       (21U)
#define EFM_FSCLR_COLERRCLR1                           (0x00200000UL)

/* \brief EFM 寄存器定义*/
typedef struct {
    volatile uint32_t FAPRT;
    volatile uint32_t KEY1;
    volatile uint32_t KEY2;
    uint8_t           RESERVED0[8];
    volatile uint32_t FSTP;
    volatile uint32_t FRMC;
    volatile uint32_t FWMC;
    volatile uint32_t FSR;
    volatile uint32_t FSCLR;
    volatile uint32_t FITE;
    volatile uint32_t FSWP;
    uint8_t           RESERVED1[16];
    volatile uint32_t CHIPID;
    uint8_t           RESERVED2[12];
    volatile uint32_t UQID0;
    volatile uint32_t UQID1;
    volatile uint32_t UQID2;
    uint8_t           RESERVED3[164];
    volatile uint32_t MMF_REMPRT;
    volatile uint32_t MMF_REMCR0;
    volatile uint32_t MMF_REMCR1;
    uint8_t           RESERVED4[116];
    volatile uint32_t WLOCK;
    uint8_t           RESERVED5[12];
    volatile uint32_t F0NWPRT0;
    volatile uint32_t F0NWPRT1;
    volatile uint32_t F0NWPRT2;
    volatile uint32_t F0NWPRT3;
    volatile uint32_t F1NWPRT0;
    volatile uint32_t F1NWPRT1;
    volatile uint32_t F1NWPRT2;
    volatile uint32_t F1NWPRT3;
} hc32f4a0_efm_regs_t;

#define HC32F4A0_EFM    ((hc32f4a0_efm_regs_t *)HC32F4A0_EFM_BASE)

#ifdef __cplusplus
}
#endif  /* __cplusplus  */

#endif

